package cn.admin.controller;

import cn.admin.config.key.RequestKey;
import cn.admin.entity.IdCardPicture;
import cn.admin.service.IdCardPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 13:59 2019/4/21
 */
@Controller
@RequestMapping("/idcard")
@CrossOrigin
public class IdCardPictureController {

    @Autowired
    private IdCardPictureService idCardPictureService;



    @GetMapping("/{user_id}/look")
    public String lookIdCard(@PathVariable("user_id")int user_id,HttpServletRequest request){
        request.setAttribute(RequestKey.REQUEST_USER_ID,user_id);
        return "/lookidcard";
    }






    @RequestMapping("/{user_id}/getPositive")
    public void getPositive(HttpServletRequest request,
                            HttpServletResponse response,
                            @PathVariable("user_id") int user_id) throws Exception {
        IdCardPicture cardById = idCardPictureService.getCardById(request, user_id);
        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(cardById.getCard_positive());
    }


    @RequestMapping("/{user_id}/getReverseSide")
    public void getReverseSide(HttpServletRequest request,
                               HttpServletResponse response,
                               @PathVariable("user_id") int user_id) throws Exception {
        System.out.println("打印");
        IdCardPicture cardById = idCardPictureService.getCardById(request, user_id);
        ServletOutputStream outputStream = response.getOutputStream();
        outputStream.write(cardById.getCard_reverse_side());
    }

}
